/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;


import com.mysql.jdbc.Statement;
import java.sql.Connection;
import java.sql.Savepoint;
import pojo.ChiTietHoaDonPOJO;

/**
 *
 * @author HP
 */
public class ChiTietHoaDonDAO {
    MySqlDataAccessHelper helper=new MySqlDataAccessHelper();
    public boolean themChiTietHoaDon(ChiTietHoaDonPOJO ct)
    {
        boolean kq=false;
        try
        {
            Connection cn=null;
            helper.open();
            cn=helper.getConnection();
            cn.setAutoCommit(false);
            String sql=String.format("Insert into ChiTietHoaDon(MaHoaDon,MaSach,SoLuongBan,GiaBan)" +
                    "values (%d,'%s',%d,%f)", ct.getMaHoaDon(),ct.getMaSach(),ct.getSoLuongBan(),ct.getGiaBan());
            Statement state=(Statement) cn.createStatement();
            Savepoint save=cn.setSavepoint();
            int n=-1;
            n=state.executeUpdate(sql);
            if(n>0)
            {
                cn.commit();
                kq=true;
            }
            else
            {
                cn.rollback(save);
            }
        }

        catch(Exception ex)
        {

        }
        helper.close();
        return kq;
    }
}
